package com.baozou.app.activity;



import java.util.List;

import android.content.ContentValues;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;

import com.baozou.R;
import com.baozou.app.adapter.BookmarkListAdapter;
import com.baozou.framework.base.BaseActivity;
import com.baozou.framework.util.Db;
public class BookmarkListActivity extends BaseActivity {
	
	ListView listView;
	Db db;
	List<ContentValues> data;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.bookmark_list);
		
		listView = (ListView)findViewById(R.id.bookmark_list_list);
		
		db = new Db(this);
		data = db.queryAll();
		ListAdapter listAdapter = new BookmarkListAdapter(this,data);
		listView.setAdapter(listAdapter);
		
		listView.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int position,
					long arg3) {
				// TODO Auto-generated method stub
				ContentValues cv = data.get(position);
				BookmarkListActivity.this.setResult(
						1, 
						new Intent(
								BookmarkListActivity.this,
								PicFlipperActivity.class).putExtra("bk_index",cv.getAsInteger("bk_index")));
				db.close();
				BookmarkListActivity.this.finish();
			}
		});
	}
	
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		// TODO Auto-generated method stub
		if(keyCode == KeyEvent.KEYCODE_BACK){
			db.close();
		}
		return super.onKeyDown(keyCode, event);
	}
}
